package com.example.administrator.myapplication;

import android.support.annotation.IdRes;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.Toast;

public class Main3Activity extends AppCompatActivity {

    private RadioGroup radioGroup;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
    }

    private void initData() {

    }

    private void initEvent() {
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                Toast.makeText(Main3Activity.this, checkedId + "", Toast.LENGTH_SHORT).show();
//           if(checkedId  ==0){
                if (checkedId == R.id.nan) {
                    Toast.makeText(Main3Activity.this, "您选择了男生", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(Main3Activity.this, "您选择了女生", Toast.LENGTH_SHORT).show();
                }
            }
            });
        }
    }
